package com.jdk.learn.exam.gui;

import org.junit.Test;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * Created by ricky
 * on 2018/2/28.
 */
public class Graphics2DDemo {

    /**
     * 创建2d绘图对象
     */
    @Test
    public void create2D() {

        BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphics2D = image.createGraphics();

        /**
         * 自定义面板
         */
        class MyPanel extends JPanel {
            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g;
            }
        }
    }

    public static void main(String[] args) {
        JFrame frame = GUIUtils.getDefaultFrame("画图");

        MyPanel panel2 = new MyPanel();
        panel2.setSize(300,200);
        frame.getContentPane().add(panel2, BorderLayout.CENTER);
        /**
         * 自定义面板
         */
        /*class MyPanel extends JPanel {
            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g;
                g2d.setColor(Color.RED);
            g2d.drawRoundRect(30,40,130,150,50,50);//圆角长方形
                g2d.drawRoundRect(73,32,56,37,10,16);//圆角长方形
                System.out.println("---------");
            }
        }*/



    }

}

/**
 * 自定义面板
 */
class MyPanel extends JPanel {
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.green);
        g.fillOval(150,150,70,70);

        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(Color.RED);
        g2d.drawRoundRect(30, 40, 100, 70, 50, 50);//圆角长方形
//        g2d.drawRoundRect(73,32,56,37,10,16);//圆角长方形
        System.out.println("---------");

        g2d.setColor(Color.BLUE);
        g2d.drawRect(140, 40, 70, 70);//正方形
    }
}
